<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#assign css>
<style>
</style>
</#assign>
<#assign js>
<script>
    function del(id) {
        layer.confirm('确定删除吗?', {icon: 3, title: '提示'}, function (index) {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "${ctx!}/user/delete/" + id,
                success: function (res) {
                    layer.msg(res.message, {time: 2000}, function () {
                        location.reload();
                    });
                }
            });
        });
    }




    $('#table').bootstrapTable({
        url: "${ctx!}/user/indexdata",
        dataType: "json",
        striped: true,
        columns: [
            // {
            //     checkbox: true,
            //     visible: true                  //是否显示复选框
            // },
            {
                title: 'ID',
                field: 'id',
                align: 'center'
            },
            {
                title: '账号',
                field: 'userName',
                align: 'center',
                valign: 'middle',
            },
            {
                title: '昵称',
                field: 'nickName',
                align: 'center'
            },
            {
                title: 'sex',
                field: 'sex',
                align: 'center',
                formatter:function(value,row,index){
                    if(value==1){
                        return '<span class="label label-danger">男</span>';
                    }else{
                        return '   <span class="label label-info">女</span>';
                    }
                }
            },
            {
                title: '联系电话',
                field: 'telephone',
                align: 'center',
            },
            {
                title: '邮箱',
                field: 'email',
                align: 'center',
            },
            {
                title: '住址',
                field: 'address',
                align: 'center',
            },
            {
                title: '删除状态',
                field: 'deleteStatus',
                align: 'center',
                formatter:function(value,row,index){
                    if(value==1){
                        return '<span class="label label-danger">已删除</span>';
                    }else{
                        return '   <span class="label label-info">未删除</span>';
                    }
                }
            },
            {
                title: '锁定',
                field: 'locked',
                align: 'center',
                formatter:function(value,row,index){
                    if(value==1){
                        return '<span class="label label-danger">已锁定</span>';
                    }else{
                        return '   <span class="label label-info">未锁定</span>';
                    }
                }
            },
            {
                title: '创建时间',
                field: 'createTime',
                align: 'center',
                sortable: true
            },
            {
                title: '操作',
                field: '',
                align: 'center',
                formatter:function(value,row,index){
                   var e ='  <@shiro.hasPermission name="system:user:edit">'+
                       ' <a class="btn btn-sm btn-primary" href="${ctx!}/user/edit/'+row.id+'">编辑</a>'+
                     ' </@shiro.hasPermission>'+
                        '  <@shiro.hasPermission name="system:user:grant">'+
                       ' <a class="btn btn-sm btn-warning" href="${ctx!}/user/grant/'+row.id+'">分配角色</a>'+
                  '  </@shiro.hasPermission>'+
                        '   <@shiro.hasPermission name="system:user:delete">'+
                        '<button class="btn btn-sm btn-danger" onclick="del('+row.id+')">删除</button>'+
                    '</@shiro.hasPermission>';
                    return e;
                }
            }
        ] ,
        queryParamsType:'',//默认值为 'limit' ,在默认情况下 传给服务端的参数为：offset,limit,sort
        // 设置为 ''  在这种情况下传给服务器的参数为：pageSize,pageNumber
        queryParams: function queryParams(params){
            var param = {
                account:$("#account").val(),
                pageNumber: params.pageNumber,
                pageSize: params.pageSize,
                sortName: params.sortName,      //排序列名
                sortOrder: params.sortOrder //排位命令（desc，asc）

            };
            return param;
        },
        //其他主要参数
        pageNumber: 1, //初始化加载第一页，默认第一页
        pageList: [5,10,15,20], //每页的记录行数（*）
        // search: true,  //显示查询框
        sidePagination: 'server',  //服务端分页
        pagination: true, //是否显示分页（*）
        sortable: true,                     //是否启用排序
        classes:"table-no-bordered",
        sortOrder: "asc"                   //排序方式
    });





</script>
</#assign>
<@layout title="用户管理" active="user">
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        用户列表
        <small>一切从这里开始</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-cog"></i> 系统</a></li>
        <li><a href="#"><i class="fa fa-list-ul"></i> 用户管理</a></li>
        <li class="active"><i class="fa fa-table"></i> 用户列表</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <!-- Default box -->
    <div class="box box-primary">
        <div class="box-header">
        <@shiro.hasPermission name="system:user:add">
            <a class="btn btn-sm btn-success" href="${ctx!}/user/add">新增</a>
        </@shiro.hasPermission>
            <a class="btn btn-sm btn-success " href="${ctx!}/user/index">刷新</a>
        </div>
        <div class="box-body table-responsive">
            <table id="table" class="table table-striped">
               <#-- <tr>
                    <th>ID</th>
                    <th>账户名</th>
                    <th>昵称</th>
                    <th>性别</th>
                    <th>电话</th>
                    <th>邮箱</th>
                    <th>住址</th>
                    <th>删除状态</th>
                    <th>锁定</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
                <#list pageInfo.content as userInfo>
                <tr>
                    <td>${userInfo.id}</td>
                    <td>${userInfo.userName}</td>
                    <td>${userInfo.nickName}</td>
                    <td>
                        <#if userInfo.sex == 1>
                            <span class="label label-info">男</span>
                        <#elseif userInfo.sex == 0>
                            <span class="label label-danger">女</span>
                        <#else >
                            <span class="label label-warning">未知</span>
                        </#if>
                    </td>
                    <td>${userInfo.telephone}</td>
                    <td>${userInfo.email}</td>
                    <td>${userInfo.address}</td>
                    <td>
                        <#if userInfo.deleteStatus == 1>
                            <span class="label label-danger">已删除</span>
                        <#else>
                            <span class="label label-info">未删除</span>
                        </#if>
                    </td>
                    <td>
                        <#if userInfo.locked == 1>
                            <span class="label label-danger">已锁定</span>
                        <#else>
                            <span class="label label-info">未锁定</span>
                        </#if>

                    </td>
                    <td>${userInfo.createTime}</td>
                    <td>
                    <@shiro.hasPermission name="system:user:edit">
                        <a class="btn btn-sm btn-primary" href="${ctx!}/user/edit/${userInfo.id}">编辑</a>
                    </@shiro.hasPermission>
                    <@shiro.hasPermission name="system:user:grant">
                        <a class="btn btn-sm btn-warning" href="${ctx!}/user/grant/${userInfo.id}">分配角色</a>
                    </@shiro.hasPermission>
                    <@shiro.hasPermission name="system:user:delete">
                        <button class="btn btn-sm btn-danger" onclick="del(${userInfo.id})">删除</button>
                    </@shiro.hasPermission>
                    </td>
                </tr>
                </#list>-->
            </table>
        </div>
        <!-- /.box-body -->
       <#-- <div class="box-footer clearfix">
            <@macro.page pageInfo=pageInfo url="${ctx!}/user/index?" />
        </div>-->
    </div>
    <!-- /.box -->

</section>
<!-- /.content -->
</@layout>